package com.gmzg.gmzgnews.news.view;


import android.content.res.ColorStateList;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gmzg.gmzgnews.R;
import com.gmzg.gmzgnews.news.adapters.CommonFragmentPagerAdapter;
import com.gmzg.gmzgnews.news.fragments.AmuseFragment;
import com.gmzg.gmzgnews.news.fragments.BaseFragment;
import com.gmzg.gmzgnews.news.fragments.HeadFragment;
import com.gmzg.gmzgnews.news.fragments.SelecteFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class NewsFragment extends Fragment {

    private TabLayout mTabLayout;
    private ViewPager mViewPager;

    public NewsFragment() {
        // Required empty public constructor
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_frist, container, false);
        // 1. TabLayout 可以使用代码添加多个  Tab
        // 2. 可以与ViewPager直接联动，
        mTabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
        mTabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.white));
        mTabLayout.setTabTextColors(ColorStateList.valueOf(getResources().getColor(R.color.white)));
//        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mViewPager = (ViewPager) view.findViewById(R.id.news_pager);
        List<BaseFragment> fragmentList = new ArrayList<>();
        fragmentList.add(new HeadFragment());
        fragmentList.add(new SelecteFragment());
        fragmentList.add(new AmuseFragment());
//        fragmentList.add(new SportsFragment());
//        fragmentList.add(new VideoFragment());
//        fragmentList.add(new CarFragment());
//        fragmentList.add(new FashionFragment());
//        fragmentList.add(new PictureFragment());
        CommonFragmentPagerAdapter adapter = new CommonFragmentPagerAdapter(
                getChildFragmentManager(),
                fragmentList
        );
        mViewPager.setOffscreenPageLimit(3);
        mViewPager.setAdapter(adapter);
        mTabLayout.setupWithViewPager(mViewPager);
        return view;
    }

}
